package com.flyqiu.common.user;

/**
 * 用户认证工具类
 */
public class FlyQiuUserTools {
    private final static ThreadLocal<FlyQiuUser> cache = new ThreadLocal<>();

    /**
     * 设置用户认证信息
     *
     * @param flyQiuFlowAuthentication 用户信息
     */
    public static void setAuthentication(FlyQiuUser flyQiuFlowAuthentication) {
        cache.set(flyQiuFlowAuthentication);
    }

    /**
     * 获取用户认证信息
     *
     * @return 用户信息
     */
    public static FlyQiuUser getAuthentication() {
        return cache.get();
    }

    public static String getTenantId() {
        FlyQiuUser authentication = getAuthentication();
        if (authentication == null) {
            return null;
        }
        return authentication.getTenantId();
    }

    public static void remove() {
        cache.remove();
    }
}
